package com.alm.handle.util;

import com.alibaba.fastjson.JSON;
import com.alm.common.utils.bean.BeanUtils;
import com.alm.entity.DevMeterCurrent;
import com.alm.handle.core.domain.entity.SysDevCurrentData;
import com.alm.handle.core.domain.entity.SysDevCurrentData_s;
import com.alm.handle.core.domain.entity.rs.GetWayUpEleDataRS;
import com.alm.handle.core.domain.entity.vo.CurrentVo;

import java.math.BigDecimal;

public class ELeCurrentUtil {
    public  static  BigDecimal One_Hundred=new BigDecimal(100);

    public  static  BigDecimal Thousand=new BigDecimal(1000);

    public  static  BigDecimal Ten=new BigDecimal(10);

    public static CurrentVo replaceData(DevMeterCurrent current){
        CurrentVo currentVo=new CurrentVo();
        currentVo.setDeviceMac(current.getDeviceId());
        currentVo.setOnlineStatus(1);
        currentVo.setRelayStatus(current.getRelayStatus());
        currentVo.setWorkStatus(current.getWorkStatus());
        currentVo.setVoltage(current.getVoltage());
        currentVo.setCurrent(current.getElectricCurrent());
        currentVo.setActivePower(current.getActivePower());
        currentVo.setFrequency(current.getFrequency());
        currentVo.setPowerFactor(current.getPowerFactor());
        currentVo.setEnergy(current.getEnergy());
        currentVo.setLineNo(current.getMsgNo());
        currentVo.setTemperature(current.getTemperature());
       // currentVo.setNetWorkType(current);
        if(currentVo.getRefreshTime() == null){
            currentVo.setRefreshTime(System.currentTimeMillis());
        }
        return currentVo;
    }
    public static SysDevCurrentData replaceData(CurrentVo current){
        SysDevCurrentData currentVo=new SysDevCurrentData();
        currentVo.setDeviceId(current.getDeviceMac());
        if(current.getVoltage()!=null)
        currentVo.setVoltage(new BigDecimal(current.getVoltage()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getCurrent()!=null)
        currentVo.setElectricCurrent(new BigDecimal(current.getCurrent()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getActivePower()!=null)
        currentVo.setActivePower(new BigDecimal(current.getActivePower()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getFrequency()!=null)
        currentVo.setFrequency(new BigDecimal(current.getFrequency()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getEnergy()!=null)
        currentVo.setEnergy(new BigDecimal(current.getEnergy()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getPowerFactor()!=null)
            currentVo.setPowerFactor(new BigDecimal(current.getPowerFactor()).setScale(4,BigDecimal.ROUND_CEILING));
        currentVo.setRelayStatus(current.getRelayStatus());
        currentVo.setWorkStatus(current.getWorkStatus());
        currentVo.setModifyTime(current.getRefreshTime());
        currentVo.setTemperature(current.getTemperature());
        //currentVo.setNetworkType(current.getNetWorkType());
        return currentVo;
    }
    public static SysDevCurrentData_s replaceDataByS(CurrentVo current){
        SysDevCurrentData_s currentData_s=new SysDevCurrentData_s();
        currentData_s.setDevid(current.getDeviceMac());
        currentData_s.setLineNo(current.getLineNo());
        currentData_s.setRelayStatus(current.getRelayStatus());
        currentData_s.setWorkStatus(current.getWorkStatus());
        if(current.getCurrent()!=null)
            currentData_s.setElectricCurrent(new BigDecimal(current.getCurrent()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getPowerFactor()!=null)
            currentData_s.setPowerFactor(new BigDecimal(current.getPowerFactor()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getEnergy()!=null)
            currentData_s.setEnergy(new BigDecimal(current.getEnergy()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getEnergy()!=null)
            currentData_s.setEnergy(new BigDecimal(current.getEnergy()).setScale(4,BigDecimal.ROUND_CEILING));
        if(current.getActivePower()!=null)
            currentData_s.setActivePower(new BigDecimal(current.getActivePower()).setScale(4,BigDecimal.ROUND_CEILING));
        return currentData_s;
    }
    public static CurrentVo resetData(CurrentVo oldData,CurrentVo newData){
        if(newData==null){
            return oldData;
        }
        if(newData.getOnlineStatus()!=null){
            oldData.setOnlineStatus(newData.getOnlineStatus());
        }
        if(newData.getRelayStatus()!=null){
            oldData.setRelayStatus(newData.getRelayStatus());
        }
        if(newData.getWorkStatus()!=null){
            oldData.setWorkStatus(newData.getWorkStatus());
        }
        if(newData.getVoltage()!=null){
            oldData.setVoltage(newData.getVoltage());
        }
        if(newData.getCurrent()!=null){
            oldData.setCurrent(newData.getCurrent());
        }
        if(newData.getActivePower()!=null){
            oldData.setActivePower(newData.getActivePower());
        }
        if(newData.getFrequency()!=null){
            oldData.setFrequency(newData.getFrequency());
        }
        if(newData.getPowerFactor()!=null){
            oldData.setPowerFactor(newData.getPowerFactor());
        }
        if(newData.getEnergy()!=null){
            oldData.setEnergy(newData.getEnergy());
        }
        if(newData.getTemperature()!=null){
            oldData.setTemperature(newData.getTemperature());
        }
        if(newData.getNetWorkType()!=null){
            oldData.setNetWorkType(newData.getNetWorkType());
        }
        oldData.setRefreshTime(System.currentTimeMillis());
        return oldData;
    }

    public static GetWayUpEleDataRS resetDataByGW(GetWayUpEleDataRS oldData, GetWayUpEleDataRS newData){
        if(newData.getActivePower()!=null){
            oldData.setActivePower(newData.getActivePower());
        }
        if(newData.getPowerFactor()!=null){
            oldData.setPowerFactor(newData.getPowerFactor());
        }
        if(newData.getElectricCurrent()!=null){
            oldData.setElectricCurrent(newData.getElectricCurrent());
        }
        if(newData.getRelayStatus()!=null){
            oldData.setRelayStatus(newData.getRelayStatus());
        }
        if(newData.getVoltage()!=null){
            oldData.setVoltage(newData.getVoltage());
        }
        if(newData.getWorkStatus()!=null){
            oldData.setWorkStatus(newData.getWorkStatus());
        }
        if(newData.getNetWorkType()!=null){
            oldData.setNetWorkType(newData.getNetWorkType());
        }
        if(newData.getGetWayMac()!=null){
            oldData.setGetWayMac(newData.getGetWayMac());
        }
        oldData.setDevId(newData.getDevId());
        return oldData;
    }
}
